//
//  ViewController.m
//  11207
//
//  Created by student on 16/3/3.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSArray *areas;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *path=[[NSBundle mainBundle]pathForResource:@"area1" ofType:@"plist"];
    self.areas=[NSArray arrayWithContentsOfFile:path];
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CELL"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.areas.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *arr=[[NSArray alloc]init];
    arr=self.areas[section][@"Cities"];
    return arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"CELL"];
    NSArray *arr=[[NSArray alloc]init];
    arr=self.areas[indexPath.section][@"Cities"];
    cell.textLabel.text=arr[indexPath.row][@"city"];
    return cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *arr=[[NSString alloc]init];
    arr=self.areas[section][@"State"];
    return  arr;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    NSMutableArray *arr=[[NSMutableArray alloc]init];
    for(int i=0;i<self.areas.count;i++)
    {
        [arr addObject:self.areas[i][@"State"]];
    }
    return arr;
}
@end
